#!/bin/bash

# 参数： 服务名、版本号
S_NAME=sojson-ui
S_VERSION=1.0.0

# 判断是否有原镜像, 有则删除该镜像
S_IMG=$(docker images -q --filter reference=hub.unionlive.com/$S_NAME*:*)
if [ "x" == "x$S_IMG" ] ; then
    echo "No image for name hub.unionlive.com/$S_NAME"
else
    DOCKER_IMAGE_RM="docker image rm $S_IMG"
    echo "> $DOCKER_IMAGE_RM"
    eval $DOCKER_IMAGE_RM
fi
# ----------------------------------------------------------------------------------------------------------------------
# 推送镜像到仓库
S_HUB="hub.unionlive.com/$S_NAME:$S_VERSION"
docker build --tag $S_HUB ./docker/
docker push $S_HUB
echo "> docker push $S_HUB"
# ----------------------------------------------------------------------------------------------------------------------

echo "build push success ......"
